<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>模糊匹配查询 | Elasticsearch: 权威指南 | Elastic</title>
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
</head>
<body>
<div class="main-container">
    <section id="content">
        
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原文地址: <a href="https://www.elastic.co/guide/cn/elasticsearch/guide/current/fuzzy-match-query.html" rel="nofollow">https://www.elastic.co/guide/cn/elasticsearch/guide/current/fuzzy-match-query.html</a>, 版权归 www.elastic.co 所有<br/>
                            英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/fuzzy-match-query.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/guide/current/fuzzy-match-query.html</a>
                            </div>
                        <!-- start body -->
                  <div class="page_header">
<b>请注意:</b><br>本书基于 Elasticsearch 2.x 版本，有些内容可能已经过时。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch: 权威指南</a></span>
»
<span class="breadcrumb-link"><a href="languages.html">处理人类语言</a></span>
»
<span class="breadcrumb-link"><a href="fuzzy-matching.html">拼写错误</a></span>
»
<span class="breadcrumb-node">模糊匹配查询</span>
</div>
<div class="navheader">
<span class="prev">
<a href="fuzzy-query.html">« 模糊查询</a>
</span>
<span class="next">
<a href="fuzzy-scoring.html">模糊性评分 »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="fuzzy-match-query"></a>模糊匹配查询 (Fuzzy match Query)<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elasticsearch-cn/elasticsearch-definitive-guide/edit/cn/270_Fuzzy_matching/40_Fuzzy_match_query.asciidoc">edit</a>
</h2>
</div></div></div>
<p><code class="literal">match</code> 查询支持开箱即用的模糊匹配：</p>
<div class="pre_wrapper lang-json">
<pre class="programlisting prettyprint lang-json">GET /my_index/my_type/_search
{
  "query": {
    "match": {
      "text": {
        "query":     "SURPRIZE ME!",
        "fuzziness": "AUTO",
        "operator":  "and"
      }
    }
  }
}</pre>
</div>
<p>查询字符串首先进行分析，会产生词项 <code class="word">surprize, me</code> ，并且每个词项根据指定的 <code class="literal">fuzziness</code> 进行模糊化。</p>
<p>同样， <code class="literal">multi_match</code> 查询也支持 <code class="literal">fuzziness</code> ，但只有当执行查询时类型是 <code class="literal">best_fields</code> 或者 <code class="literal">most_fields</code> ：</p>
<div class="pre_wrapper lang-json">
<pre class="programlisting prettyprint lang-json">GET /my_index/my_type/_search
{
  "query": {
    "multi_match": {
      "fields":  [ "text", "title" ],
      "query":     "SURPRIZE ME!",
      "fuzziness": "AUTO"
    }
  }
}</pre>
</div>
<p><code class="literal">match</code> 和 <code class="literal">multi_match</code> 查询都支持 <code class="literal">prefix_length</code> 和 <code class="literal">max_expansions</code> 参数。</p>
<div class="tip admon">
<div class="icon"></div>
<div class="admon_content">
<p>模糊性（Fuzziness）只能在 <code class="literal">match</code> 和 <code class="literal">multi_match</code> 查询中使用。不能使用在短语匹配(<code class="word">phrase matching</code>)、常用词项(<code class="word">common terms</code>) 或 <code class="literal">cross_fields</code>匹配中。</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="fuzzy-query.html">« 模糊查询</a>
</span>
<span class="next">
<a href="fuzzy-scoring.html">模糊性评分 »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>